package net.esj.basic.core.engine.support.validator.constraints.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import net.esj.basic.core.engine.support.validator.constraints.PojoExist;
import net.esj.basic.pojo.PrimaryKey;
import net.esj.basic.utils.Validators;

public class PojoExistValidator implements ConstraintValidator<PojoExist, PrimaryKey> {

	@Override
	public void initialize(PojoExist arg0) {
	}

	@Override
	public boolean isValid(PrimaryKey pojo, ConstraintValidatorContext arg1) {
		if(pojo==null){
			return false;
		}
		if(Validators.isEmpty(pojo.getId())){
			return false;
		}
		return true;
	}

}
